#!/bin/sh

if [ -f "ffmpeg.pid" ]; then
	kill "$(cat ffmpeg.pid)"
	rm -f ffmpeg.pid
	dunstify -a ffmpeg -h string:x-dunst-stack-tag:FFMPEG "ffmpeg" "Recording stopped"
else
	default_sink="$(pactl info @DEFAULT_SINK@ | grep "^Default Sink" | awk '{print $3}').monitor"
	ffmpeg -f x11grab -i :0.0 -f pulse -ac 2 -i "$default_sink" -f pulse -i default -map 0 -map 1 -map 2 "$1" &
	echo $! > ffmpeg.pid
	dunstify -a ffmpeg -h string:x-dunst-stack-tag:FFMPEG "ffmpeg" "Recording started"
fi
